package observer

class User constructor(var userName: String) : Observer<String> {

    //接受消息的回调
    private var onReceive: OnReceive<String>? = null

    //消息更细
    override fun update(msg: String) {
        onReceive?.onUpdateReceived(this, msg)
    }

    //订阅
    override fun subscription(observable: Observable<String>): User {
        observable.register(this)
        return this
    }

    //取消订阅
    override fun unSubscription(observable: Observable<String>) {
        observable.unregister(this)
    }

    //设置消息回调
    override fun onReceived(onReceive: OnReceive<String>) {
        this.onReceive = onReceive
    }

}